from war_utils import *

class Hunter:
    def __init__(self, name, hunter_type, life, attack_value, hit_rate, magic_value):
        self.name = name
        self.hunter_type = hunter_type
        self.life = life
        self.attack_value = attack_value
        self.hit_rate = hit_rate
        self.magic_value = magic_value
        
    def op_deal_with(self, op_num, attack_obj):
        if op_num == 1:
            self.attack(attack_obj)
        else:
            self.sleep()
            
    def attack(self, attack_obj):
        if probability_judge(self.hit_rate):
            attack_obj.life -= self.attack_value
        else:
            print("%s猎人，小手一抖，雷击箭射歪了。" % self.name)
            
    def sleep(self):
        print("猎人开始装箭") 

class Soldier:
    def __init__(self, name, soldier_type, life, attack_value, step, distance):
        self.name = name
        self.soldier_type = soldier_type
        self.life = life
        self.attack_value = attack_value
        self.step = step
        self.distance = distance
        
    def op_deal_with(self, op_num, attack_obj):
        if op_num == 1:
            self.attack(attack_obj)
        else:
            self.sleep()
            
    def attack(self, attack_obj, hit_rate):
        if probability_judge(hit_rate):
            attack_obj.life -= self.attack_value
        else:
            print("%s士兵，开枪不中，浪费子弹。" % self.name)
            
    def sleep(self):
        print("士兵正在休息中。")

game_is_running = True
rounds = 1

hunter = Hunter("sova", "雷击箭", 150, 75, 0.7, 100)
soldier1 = Soldier("yoru", "时空跳跃", 300, 40, 2, 8)

print("游戏开始")
while game_is_running:
    print("---------第%i回合---------" % rounds)
    if hunter.life <= 0 or soldier1.life <= 0:
        game_is_running = False
        break
    print("法师的回合:")
    if hunter.life > 0 and probability_judge(hunter.hit_rate):
        if soldier1.distance <= 8:
            print(">>>>%s使用了%s，击中了%s，造成了%i点伤害" % (hunter.name, hunter.hunter_type, soldier1.name, hunter.attack_value))
            soldier1.life -= hunter.attack_value
        else:
            print(">>>>%s使用了%s，未能击中，造成了0点伤害" % (hunter.name, hunter.hunter_type, soldier1.name, 0*hunter.attack_value))
            soldier1.life -= 0*hunter.attack_value
    else:
        print(">>>>%s使用了%s，小手tm一抖" % (hunter.name, hunter.hunter_type))

    print("\n战士的回合")
    if soldier1.life > 0:
        print("您的剩余血量：%i" % soldier1.life)
        if soldier1.distance <= 8:
            soldier1.attack(hunter, 0.6)
            print(">>>>%s开了一枪，造成了%i点伤害" % (soldier1.name, soldier1.attack_value))
        else:
            soldier1.distance += soldier1.step
            print(">>>>%s时空跳跃离开，距离法师还有%i个单位" % (soldier1.name, soldier1.distance))
        soldier1.state = int(input("请输入您下回合需要执行的操作，1表示前进，0表示时空跳跃:"))
    else:
        print(">>>>%s已经死亡，无法进行操作。" % soldier1.name)
    print("-------------此回合结束------------\n")

    rounds += 1


if hunter.life > 0:
    print("猎人胜！")
else:
    print("战士胜！")
